Skip to content

Implement Check Detection System#79

Open
walshb421 wants to merge 1 commit intoadd-fen-supportfrom
issue-76-check-detection
Open

Implement Check Detection System#79
walshb421 wants to merge 1 commit intoadd-fen-supportfrom
issue-76-check-detection

Conversation

@walshb421
Copy link
Owner

Summary

This PR implements a comprehensive check detection system for the chess engine, addressing issue #76.

New Methods Added to ChessBoard

  • get_king_position(color): Returns the (row, col) tuple of the specified color king
  • is_square_attacked(square, by_color): Returns True if any piece of the attacking color can reach the given square
  • is_in_check(color): Returns True if the king of the specified color is currently in check
  • would_be_in_check(move, color): Simulates a move and checks if it would leave the king in check

Updated Move Validation

  • can_move_piece(): Now filters out any move that would leave the king in check
  • castling_check(): Updated to enforce all castling rules (cannot castle out of, through, or into check)

Game State

  • Added in_check boolean to the game state JSON

How to Test

  1. Basic Check Detection

    • Load FEN: rnbqkbnr/pppp1ppp/8/4p3/6P1/5P2/PPPPP2P/RNBQKBNR b KQkq - 0 2
    • Move black queen to h4 (Qh4+) - white king should be in check
    • White should only be able to make moves that escape check
  2. Pinned Piece

    • Load FEN: rnb1kbnr/pppp1ppp/8/4p3/7q/5NP1/PPPPP2P/RNBQKB1R w KQkq - 0 3
    • The g3 pawn is pinned - try moving it (should be blocked)
  3. Castling Through Check

    • Load FEN: r3k2r/pppp1ppp/8/4p3/1b6/8/PPPPPPPP/R3K2R w KQkq - 0 1
    • White cannot castle queenside (d1 is attacked by bishop)

Closes #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant